﻿using Study.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApp4
{
    /// <summary>
    /// MyCombox.xaml 的交互逻辑
    /// </summary>
    public partial class MyCombox : Window
    {
        public MyCombox()
        {
            InitializeComponent();

            this.Loaded += (s, e) =>
            {
                List<Person> data = new List<Person>()
                {
                    new Person() { Id = 1, Name = "张三", Address = "江西省抚州市宜黄县" },
                    new Person() { Id = 2, Name = "李四", Address = "广东省深圳市龙岗区" },
                    new Person() { Id = 3, Name = "王五", Address = "北京市西二旗上地" },
                    new Person() { Id = 4, Name = "关公", Address = "北京市东城区" }
                };
                combox.ItemsSource = data;
            };
        }

        private void combox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            TbValue.Text= combox.SelectedValue.ToString();
            var person = combox.SelectedItem as Person;
            TbInfo.Text = $"Id:{person.Id},Name:{person.Name},Address:{person.Address}";
        }
    }
}
